const isLogin = () => !!localStorage.getItem('token');
const getToken = () => localStorage.getItem('token');
const removeUserInfo = () => {
  localStorage.removeItem('token')
  localStorage.removeItem('role')
  localStorage.removeItem('userInfo')
}
// 过滤 当前角色可以访问的 侧边导航
const filterMenus = (menus: any[]) => {
  const role = localStorage.getItem('role');
  const authMenus: any[] = [];
  menus.forEach(menu=> {
    const _menu = menu
    if (_menu.roles === '*' ||_menu.roles.includes(role)) {
      if (_menu.children) {
        _menu.children = filterMenus(_menu.children)
      }
      authMenus.push(_menu)
    }
  })
  return authMenus
}
// 过滤当前角色可以访问的路由
const filterRoutes = (routes: any[]) => {
  const role = localStorage.getItem('role');
  const authRoutes: any[] = [];
  routes.forEach((route: any)=> {
    const _route = {...route};
    if (_route.roles === '*' ||_route.roles.includes(role)) {
      if (_route.children) {
        _route.children = filterRoutes(_route.children)
      }
      authRoutes.push(_route)
    }
  })
  return authRoutes
}
export {
  isLogin,
  getToken,
  removeUserInfo,
  filterMenus,
  filterRoutes
}